package com.tanhua.admin.interceptor;

import com.tanhua.admin.service.AnalysisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 定时统计日志任务类
 */
@Slf4j
@Component
public class AnalysisTask {

    @Autowired
    private AnalysisService analysisService;

    /**
     * 定时统计日志 测试：五分钟上传一次
     * 注意：Cron表达式
     */
    @Scheduled(cron = "0 0 0-23 * * ? ")
    public void analysis() throws ParseException {
        String dateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        log.info("定时统计日志：{}",dateTime);
        analysisService.analysisLog();
        log.info("结束当前统计。");
    }

}